<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>canvas测试</title>
</head>
<body>
<canvas id="canvas" width="300" height="300"></canvas>
<script>
  function $(id){
    return document.getElementById(id);
  }

  function initial(){
    var canvas  = $('canvas');
    canvas.width = 600;
    canvas.height = 600
    ctx = canvas.getContext('2d');
    ctx.strokeRect(100,100,300,300);
    ctx.fillRect(120,120,260,260);
    ctx.clearRect(140,140,220,220);
  }

  window.addEventListener('load',initial,false)
</script>
</body>
</html>
